﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Provenance.ErrorCount;

namespace Provenance.Read.Api
{
    public class CustomExceptionFilter : IExceptionFilter
    {
        private readonly ILogger<CustomExceptionFilter> _logger;    
        public CustomExceptionFilter(ILogger<CustomExceptionFilter> logger)
        {
            _logger = logger;
        }

        public void OnException(ExceptionContext context)
        {
            _logger.LogError("全局异常过滤器发生异常"+context.Exception.Message);
            context.Result = new JsonResult(ApiResult.Failure(context.Exception.Message));
            context.ExceptionHandled = true;
        }
    }
}
